<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
    <title>悦章科技机构平台</title>
    <script src="/Public/static/jquery-2.0.3.min.js"></script>
    <script src="/Public/static/layer/layer.js"></script>
    <!--内容样式-->
    <link rel="stylesheet" href="__PUBLIC__/Home/css/style.css" />
    <link rel="stylesheet" href="__PUBLIC__/Home/css/page.css" />
</head>
<body>

<div class="main">
    <!--  头部  -->
    <include file="menu" />

    <!--  右侧内容  -->
    <div class="content">
        <div class= "ct-title">
            <div class="ctt-bt">学生管理</div>
            <div class="ctt-r">
                <form class="cttr-bd" action="" method="POST">
                    <input type="text" placeholder="请输入姓名" class="cttrb-wb" name="username">
                        <select class="cttrb-xl" name="class_id">
                            <option value="">选择班级</option>
                            <volist name="class_list" id="item">
                                <option value="{$item['id']}" <if condition="$item['id'] eq $msg['class_id']">selected</if>>{$item['name']}</option>
                            </volist>
                        </select>
                    <div class="cttrb-sj">
                        <input type="date" name="start_time" value="{$msg['start_time']}">
                        <img src="__PUBLIC__/Home/images/img_zhi.png" />
                        <input type="date" name="end_time" value="{$msg['end_time']}">
                        <div class="divclear"></div>
                    </div>
                    <button class="cttrb-cx" type="submit">查询</button>
                    <div class="cttrb-fp" onclick="showtckxsfb()">分班</div>
                    <a href="{:U('Home/Educational/addStudent')}" class="cttrb-xz">新增学生</a>
                    <div class="divclear"></div>
                </form>
                <div class="divclear"></div>
            </div>
            <div class="divclear"></div>
        </div>

        <div class="ct-sx">
<!--             <label class="cts-qx">
                <input type="checkbox">
                <span>全选</span>
                <div class="divclear"></div>
            </label> -->
            <div class="cts-tab">
                <div class='ctst-btn <if condition="$type eq 1">ctst-btn-on</if>' data-z="1" >按注册时间</div>
                <div class='ctst-btn <if condition="$type eq 2">ctst-btn-on</if>' data-z="2">按购买课程数</div>
                <div class='ctst-btn <if condition="$type eq 3">ctst-btn-on</if>' data-z="3">按登录次数</div>
                <div class='ctst-btn <if condition="$type eq 4">ctst-btn-on</if>' data-z="4">按做试卷数</div>
                <div class='ctst-btn <if condition="$type eq 5">ctst-btn-on</if>' data-z="5">按做题数</div>
                <div class='ctst-btn <if condition="$type eq 6">ctst-btn-on</if>' data-z="6">按观看视频时长</div>
                <div class="divclear"></div>
            </div>
            <div class="divclear"></div>
        </div>

        <div class="ct-table">
            <table width="100%" border="0">
                <tbody>
                <tr>
                    <!-- <th scope="col" width="2%" style="border-top-left-radius: 10px;"></th> -->
                    <th scope="col" width="5%">ID</th>
                    <th scope="col" width="7%">姓名</th>
                    <th scope="col" width="7%">所属班级</th>
                    <th scope="col" width="12%">身份证号</th>
                    <th scope="col" width="8%">手机号</th>
                    <th scope="col" width="5%">购买次数</th>
                    <th scope="col" width="5%">负责人</th>
                    <th scope="col" width="5%">来源</th>
                    <th scope="col" width="5%">登录次数</th>
                    <th scope="col" width="5%">试卷</th>
                    <th scope="col" width="5%">做题</th>
                    <th scope="col" width="8%">视频时长</th>
                    <th scope="col" width="8%">注册时间</th>
                    <th scope="col" width="13%" style="border-top-right-radius: 10px;">操作</th>
                </tr>
                <volist name="_list" id="vo">
                    <tr>
                        <!-- <td><input type="checkbox"></td> -->
                        <td>{$vo.id}</td>
                        <td>{$vo.username}</td>
                        <td>{$vo.class_name}</td>
                        <td>{$vo.id_card}</td>
                        <td>{$vo.mobile}</td>
                        <td>{$vo.c_order}</td>
                        <td>{$vo.person_charge}</td>
                        <td>
                            <if condition="$vo['source'] eq 1">
                                线上咨询
                                <elseif condition="$vo['source'] eq 2"/>
                                客户介绍
                                <elseif condition="$vo['source'] eq 3"/>
                                学生介绍
                                <elseif condition="$vo['source'] eq 4"/>
                                线下联系
                                <else/>
                                其他
                            </if>
                        </td>
                        <td>{$vo.login_count}</td>
                        <td>{$vo.c_sj}</td>
                        <td>{$vo.c_lxc}</td>
                        <td>{$vo.all_study_time}秒</td>
                        <td>{$vo.reg_time|date='Y-m-d',###}</td>
                        <td><a href="{:U('Educational/study_detail',array('id'=>$vo['id']))}">详情</a><!-- <a href="教务系统-学生管理-新增学生.html">编辑</a> --><a href="{:U('Educational/student_del',array('id'=>$vo['id']))}">删除</a></td>
                    </tr>
                </volist>
                </tbody>
            </table>
        </div>
        <div class="page">
            {$_page}
        </div>
        <!--<div class="ct-btn">
            <div class="ctb-an"><</div>
            <div class="ctb-an ctb-an-on">1</div>
            <div class="ctb-an">2</div>
            <div class="ctb-an">3</div>
            <div class="ctb-an">></div>
            <div class="divclear"></div>
        </div>-->
    </div>
</div>

<!-- 学生分班 弹出框-->
<div class="tck-demo" id="tck-xsfb">

    <div class="tk-box">
        <div class="tkb-title">
            <div class="tkbt-bt">待分班学生</div>
            <div class="tkbt-close" onClick="document.getElementById('tck-xsfb').style.display='none'">
                <img src="__PUBLIC__/Home/images/icon_delete.png" />
            </div>
            <div class="divclear"></div>
        </div>
        <div class="tkb-fpxs">
            <form class="tkbf-top">
                <!--<select class="tkbft-xl" style="width: 313px;">
                    <option>选择一级分类</option>
                </select>
                <select class="tkbft-xl" style="width: 313px;">
                    <option>选择二级分类</option>
                </select>
                <select class="tkbft-xl" style="width: 313px;margin: 10px 0 10px 0;">
                    <option>选择班级</option>
                </select>
                <div class="divclear"></div>-->
            </form>
            <div class="tkbf-nr">
                <!--<div class="tkbfn-box">
                    <span>王小二  /  男  /  15575991558</span>
                    <div class="tkbfnb-yc">
                        <img src="__PUBLIC__/Home/images/icon_yc.png" />
                    </div>
                    <div class="divclear"></div>
                </div>
                <div class="tkbfn-box">
                    <span>王小二  /  男  /  15575991558</span>
                    <div class="tkbfnb-yc">
                        <img src="__PUBLIC__/Home/images/icon_yc.png" />
                    </div>
                    <div class="divclear"></div>
                </div>
                <div class="divclear"></div>-->
            </div>
        </div>
        <div class="tkb-qr" onclick="division()">确定分班</div>
    </div>

</div>
</body>
<script type="text/javascript">
    function showtckxsfb()
    {
        var url = "{:U('Home/Educational/getNotClassStudent')}";
        $.ajax({
            type: "POST", //类型get，post
            url: url, //链接地址
            success: function(data){
                var dataObj = JSON.parse(data);
                $(".tkbf-nr").empty();
                $('.tkbf-top').empty();
                var html = "";
                //成功后函数
                if(dataObj.result == 1){
                    for(var i=0;i<dataObj.data.student.length;i++){
                        var sex = "";
                        if(dataObj.data.student[i]['sex'] == "0"){
                            sex = "未知";
                        }else if(dataObj.data.student[i]['sex'] == "1"){
                            sex = "男";
                        }else {
                            sex = "女";
                        }
                        html += "<div class='tkbfn-box aa_"+dataObj.data.student[i]['id']+"'>"+
                                "<input type='hidden' name='student_id' value='"+dataObj.data.student[i]['id']+"'>"+
                                "<span>"+dataObj.data.student[i]['username']+"  /  "+sex+"  /  "+dataObj.data.student[i]['mobile']+"</span>"+
                            "<div class='tkbfnb-yc'><img src='__PUBLIC__/Home/images/icon_yc.png' onclick='delStudent("+dataObj.data.student[i]['id']+")'/></div>"+
                            "<div class='divclear'></div></div>";
                    }

                    console.log(dataObj);
                    var top_html = "";
                    top_html += "<select class='tkbft-xl' style='width: 313px;' name='one_class_id' onchange='selectOneClass()'><option value=''>选择一级分类</option>";
                    for(var a=0;a<dataObj.data.parent.length;a++){
                        top_html += "<option value='"+dataObj.data.parent[a]['id']+"'>"+dataObj.data.parent[a]['name']+"</option>";
                    }
                    top_html += "</select>";
                    top_html += "<select class='tkbft-xl' style='width: 313px;' name='two_class_id' onchange='selectTwoClass()'><option value=''>选择二级分类</option>";
                    for(var b=0;b<dataObj.data.child.length;b++){
                        top_html += "<option value='"+dataObj.data.child[b]['id']+"'>"+dataObj.data.child[b]['name']+"</option>";
                    }
                    top_html += "</select>";
                    top_html += "<select class='tkbft-xl' style='width: 313px;margin: 10px 0 10px 0;' name='class_id1'><option value=''>选择班级</option>";
                    for(var c=0;c<dataObj.data.class.length;c++){
                        top_html += "<option value='"+dataObj.data.class[c]['id']+"'>"+dataObj.data.class[c]['name']+"</option>";
                    }
                    top_html += "</select>";
                    top_html += "<div class='divclear'></div>";
                }
                html += "<div class='divclear'></div>";

                $('.tkbf-top').append(top_html);
                $(".tkbf-nr").append(html);
                $("#tck-xsfb").show();
            },
            error:function(){
                //失败时函数
                layer.msg("失败");
            }
        })
    }

    function selectOneClass()
    {
        var cc_id = $("select[name='one_class_id']").find("option:selected").val();

        var url = "{:U('Home/Educational/getTwoClassAndClass')}";
        $.ajax({
            type: "POST", //类型get，post
            url: url, //链接地址
            data:{"cc_id":cc_id},//参数，一般post用
            success: function(data){
                var dataObj = JSON.parse(data);
                $("select[name='two_class_id']").empty();
                $("select[name='class_id1']").empty();
                $("select[name='two_class_id']").append("<option value=''>选择二级分类</option>");
                $("select[name='class_id1']").append("<option value=''>选择班级</option>");
                //成功后函数
                if(dataObj.result == 1){
                    for(var i=0;i<dataObj.data.child.length;i++){
                        $("select[name='two_class_id']").append("<option value='"+dataObj.data.child[i]['id']+"'>"+dataObj.data.child[i]['name']+"</option>");
                    }

                    for(var j=0;j<dataObj.data.class.length;j++){
                        $("select[name='class_id1']").append("<option value='"+dataObj.data.class[j]['id']+"'>"+dataObj.data.class[j]['name']+"</option>");
                    }
                }
            },
            error:function(){
                //失败时函数
                layer.msg("失败");
            }
        })
    }

    function selectTwoClass()
    {
        var cc_id = $("select[name='one_class_id']").find("option:selected").val();
        var two_class_id = $("select[name='two_class_id']").find("option:selected").val();

        var url = "{:U('Home/Educational/getClass')}";
        $.ajax({
            type: "POST", //类型get，post
            url: url, //链接地址
            data:{"cc_id":cc_id,'two_class_id':two_class_id},//参数，一般post用
            success: function(data){
                var dataObj = JSON.parse(data);
                console.log(dataObj);
                $("select[name='class_id1']").empty();
                $("select[name='class_id1']").append("<option value=''>选择班级</option>");
                //成功后函数
                if(dataObj.result == 1){

                    for(var j=0;j<dataObj.data.length;j++){
                        $("select[name='class_id1']").append("<option value='"+dataObj.data[j]['id']+"'>"+dataObj.data[j]['name']+"</option>");
                    }
                }
            },
            error:function(){
                //失败时函数
                layer.msg("失败");
            }
        })
    }

    function delStudent(id)
    {
        $(".aa_"+id).remove();
    }

    function division()
    {
        var id = "";
        $('.tkbfn-box').each(function(e){
            id += $("input[name='student_id']").eq(e).val()+",";
        })
        id = id.substring(0,id.length-1);
        var class_id1 = $("select[name='class_id1']").find("option:selected").val();
        // console.log(class_id1);return false;
        var url = "{:U('Home/Educational/division')}";
        $.ajax({
            type: "POST", //类型get，post
            url: url, //链接地址
            data:{"id":id,'class_id':class_id1},//参数，一般post用
            success: function(data){
                var dataObj = JSON.parse(data);

                //成功后函数
                if(dataObj.result == 1){
                    layer.msg(dataObj.msg);
                    setTimeout(function (){
                        window.location.href = "{:U('Home/Educational/studentList')}";
                    },1000);
                }else {
                    layer.msg(dataObj.msg);
                }
            },
            error:function(){
                //失败时函数
                layer.msg("失败");
            }
        })
    }

    $('.ctst-btn').click(function(){
        // $('.ctst-btn').removeClass('ctst-btn-on');
        // $(this).addClass('ctst-btn-on');
        // alert(123);return false;
        var type=$(this).data('z');
        var url="{:U('Home/Educational/studentList')}";
        url=url+"&type="+type;
        location.href=url;
    })
</script>
</html>
